package pe.com.bbva.targps.bo.impl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;


import pe.com.bbva.targps.bo.ConsultaGPSBO;
import pe.com.bbva.targps.dao.ConsultaGPSDAO;
import pe.com.bbva.targps.domain.ConsultaGPS;
import pe.com.stefanini.core.bo.GenericBOImpl;
import pe.com.stefanini.core.bo.Grid;
import pe.com.stefanini.core.exceptions.BOException;
import pe.com.stefanini.core.exceptions.DAOException;
import pe.com.stefanini.core.util.StringUtil;

@Service("consultaGPSBO")
@SuppressWarnings({"rawtypes", "unchecked"})
public class ConsultaGPSBOImpl extends GenericBOImpl implements ConsultaGPSBO{
	Logger logger = Logger.getLogger(this.getClass());
	@Resource
	private ConsultaGPSDAO consultaGPSDAO;

	@Override
	@Transactional(propagation=Propagation.REQUIRED)
	public void save(ConsultaGPS consultaGPS) throws BOException, DAOException {
		super.doSave(consultaGPS);
	}
	
	@Override
	public void update(ConsultaGPS consultaGPS) throws BOException {			
		try {
			super.doSave(consultaGPS);
		} catch (Exception e) {
			logger.error(StringUtil.getStackTrace(e));
			throw new BOException(e.getMessage());
		}
	}
	
	@Override
	public ConsultaGPS findById(Long id) throws BOException {
		ConsultaGPS consultaGPS = (ConsultaGPS) super.findById(ConsultaGPS.class, id);
		return consultaGPS;
	}
	
	@Override
	public List<ConsultaGPS> findProcesosCargaRango(ConsultaGPS consultaGPS, String fechaInicio, String fechaFin)throws BOException, DAOException {
		List<ConsultaGPS> listaProcesos = consultaGPSDAO.findProcesosCargaRango(consultaGPS, fechaInicio, fechaFin);
		return listaProcesos;
	}
	
	@Override
	public Grid<ConsultaGPS> findToGridGPS(List<ConsultaGPS> consultas, String order, int page, int rows) throws BOException, DAOException {
		String where="where ";
	    return super.findToGridList(consultas, where, " order by "+order,page,rows);
	}
	
	@Override
	public void delete(ConsultaGPS consultaGPS) throws BOException {
		super.delete(consultaGPS);
	}
	
}